package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.banquet.BanquetGiftInfo;
import com.yanqu.road.entity.banquet.BanquetInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class BanquetConfigDaoImpl extends TempDao {

    public Map<Integer, BanquetInfo> getBanquetInfoMap() {
        Map<Integer, BanquetInfo> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_p_banquet";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                BanquetInfo data = new BanquetInfo();
                data.setId(rs.getInt("id"));
                data.setType1(rs.getInt("type1"));
                data.setType2(rs.getInt("type2"));
                data.setOpenConsume(rs.getString("openConsume"));
                data.setCoolCd(rs.getInt("coolCd"));
                data.setBanquetTime(rs.getInt("banquetTime"));
                data.setLockReward(rs.getString("lockReward"));
                data.setSeat(rs.getInt("seat"));
                data.setFulPopularity(rs.getInt("fulPopularity"));
                data.setEndEffect(rs.getInt("endEffect"));
                data.setRobots(rs.getString("robots"));
                data.setParams(rs.getString("params"));
                data.setEndReward(rs.getString("endReward"));
                data.setTitleAdd(rs.getBoolean("isTitleAdd"));
                data.setName(rs.getString("name"));

                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, BanquetGiftInfo> getBanquetGiftInfoMap() {
        Map<Integer, BanquetGiftInfo> dataMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_p_banquet_gift";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);

            rs = call.executeQuery();
            while (rs.next()) {
                BanquetGiftInfo data = new BanquetGiftInfo();
                data.setId(rs.getInt("id"));
                data.setType1(rs.getInt("type1"));
                data.setType2(rs.getInt("type2"));
                data.setJoinConsume(rs.getString("joinConsume"));
                data.setJoinScore(rs.getString("joinScore"));
                data.setJoinReward(rs.getString("joinReward"));

                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

}
